﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;//命名空间

public partial class zhuce : System.Web.UI.Page
{

   // private static string connstr = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString().Trim();
    DataClassesDataContext db = new DataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnRegi_Click(object sender, EventArgs e)
    {
        string type = ddlRegi.SelectedValue;
        //string ID = txtID.Text.Trim();
        string name = txtLogname.Text.Trim();//从文本框中取出
        string ps = txtLogpass.Text.Trim();
        Users newUser = new Users();
        newUser.UserType = type;
        newUser.UserId = getID();
        newUser.UserPass = ps;
        newUser.UserName = name;
        db.Users.InsertOnSubmit(newUser);
        db.SubmitChanges();
          
        Response.Write("<script>alert('注册成功!');</script>");
        
    }

    protected string getID()
    {
        int maxId = -1;
        var results = from r in db.Users
                      select r;
        foreach (Users u in results)
        {
            if (int.Parse(u.UserId) > maxId)
            {
                maxId = int.Parse(u.UserId);
            }
        }
        return (maxId + 1).ToString();
    }
   
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        //txtID.Text = "";
        txtLogname.Text = "";
        txtLogpass.Text = "";
    }

   
}